﻿/* 
 * Since 2008 - 2012
 */

package com.hh.bss.project.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

import com.hh.bss.base.*;
import com.hh.bss.common.page.*;
import com.hh.bss.common.page.impl.*;
import com.hh.bss.project.dao.*;
import com.hh.bss.project.entity.*;
import com.hh.bss.project.service.*;
import com.hh.bss.project.vo.query.*;
import com.hh.bss.util.*;



@Service
@Transactional
public class ContractJobOfferPartnerServiceImpl extends BaseBusinessService<ContractJobOfferPartner, java.lang.Integer> implements ContractJobOfferPartnerService<ContractJobOfferPartner, java.lang.Integer> {

	private ContractJobOfferPartnerDao contractJobOfferPartnerDao;

	/** 增加setXXXX()方法,spring就可以通过autowire自动设置对象属性,请注意大小写 */
	public void setContractJobOfferPartnerDaoImpl(ContractJobOfferPartnerDao dao) {
		this.contractJobOfferPartnerDao = dao;
	}

	public EntityDao getEntityDao() {
		return this.contractJobOfferPartnerDao;
	}

	@Transactional(readOnly = true)
	public Page findPage(ContractJobOfferPartnerQuery query) {
		return contractJobOfferPartnerDao.findPage(query);
	}

	/**
	 * 检查 是否存在 相同的记录 及 account 和 role 一样
	 */
	@Override
	public boolean checkSameRoleAndAccount(ContractJobOfferPartner offerPartner) {

		return contractJobOfferPartnerDao.checkSameRoleAndAccount(offerPartner);
	}

	@Override
	public void addPartnerWithJob(Integer jobId) {
		contractJobOfferPartnerDao.addPartnerWithJob(jobId);
	}

	@Override
	public void updatePartnerWithJob(Integer jobId) {
		contractJobOfferPartnerDao.updatePartnerWithJob(jobId);
	}

	@Override
	/**
	 * 验证业绩是否合法
	 * 录用人选管理中，修改业绩分配的时候要求：
		1.职位负责人(MC)和合作顾问(PC)，所有是这两种参与人的业绩分配的总和，不得超过100，不让其保存，可等于100.
		2.业务助理的业绩分配(BA)，暂时不作限制。
		return true 合法 false 非法的
	 */
	public boolean validateOfferPartner(ContractJobOfferPartner offerPartner) {
		log.info("service 执行了..");
		return this.contractJobOfferPartnerDao.validateOfferPartner(offerPartner);
		/*
		 * if(offerPartner !=null){
		 * if(StringUtils.isNotEmpty(offerPartner.getRole())){ //如果是 职位负责人 和
		 * 合作顾问 验证业绩 if("MC".equals(offerPartner.getRole()) ||
		 * "PC".equals(offerPartner.getRole())){ StringBuffer hql = new
		 * StringBuffer(); hql.append(
		 * "select sum(a.percent) from  ContractJobOfferPartner a where 1=1 and (a.role='MC' or a.role='PC') and a.offerId = "
		 * +offerPartner.getOfferId()); List list =
		 * this.findByHql(hql.toString()); if(list != null && list.size() >0){
		 * Double percent = (Double)list.get(0);
		 * if((offerPartner.getPercent()+percent) >100.00d){ return false; } } }
		 * } } return true;
		 */}

	@Override
	public boolean isJobOfferPartner(ContractJobOfferPartner offerPartner) {
		return this.contractJobOfferPartnerDao.isJobOfferPartner(offerPartner);

	}

}
